package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.questionnaire.model.QuestionAnswerSheet;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;

/**
 * 回访记录
 * 
 * @author zhoulin
 * 模型评审：需要根据最新的产品类型模型调整模型，wulina 2016-09-07
 *
 */
@Entity
@Table(name = "travel_customervisitrecord")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = { @CriteriaEnhancer(impl = OrderCriteriaEnhancer.class) })
public class CustomerVisitRecord extends BaseModel {

	private static final long serialVersionUID = -3823374199719508654L;

	@Id
	@In
	@DocumentId
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long pkCustomerVisitRecord;

	/** 客户 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkCustomer")
	@IndexedEmbedded(depth = 1)
	@In
	private Customer customer;
	
	/** 意向和签约对应的回访记录关联表 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkVisit")
	@IndexedEmbedded(depth = 1)
	@In
	private Visit visit;

	/** 产品类型 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkProductType")
	@IndexedEmbedded(depth = 1)
	@In
	private ProductType productType;

	/** 访问方式 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkVisitWay")
	@IndexedEmbedded(depth = 1)
	@In
	private VisitWay visitWay;

	/** 答卷 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkQuestionAnswerSheet")
	@IndexedEmbedded(depth = 1)
	private QuestionAnswerSheet questionAnswerSheet;

	/** 时间 */
	@Column
	@Field
	@Between
	private Date visitDate;
	
	/** 回访提醒时间*/
	@Column
	@Field
	@Between
	private Date visitRemindDate;

	/** 意向 */
	@Enumerated(EnumType.STRING)
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private Intention intention;

	/** 客户访问记录类型 */
	@Enumerated(EnumType.STRING)
	@In
	@Field
	@FieldBridge(impl = EnumBridge.class)
	private RecordType recordType;

	/** 销售顾问 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkSaleConsultant")
	@IndexedEmbedded(depth = 1)
	private CommonUser saleConsultant;

	/** 沟通内容 */
	@Column
	@Field
	private String contents;

	/** 备注 */
	@Column
	@Field
	private String description;

	/** 加入其他机构 */
	@Column
	@Field
	private Boolean joinOtherOrg;

	@Version
	private Integer version;

	@JsonSerialize(using = EnumSerializer.class)
	public enum RecordType {
		Visit("来访"), Return("回访");

		private String display;

		RecordType(String display) {
			this.display = display;
		}

		public String getDisplay() {
			return display;
		}
	}

	public Long getPkCustomerVisitRecord() {
		return pkCustomerVisitRecord;
	}

	public void setPkCustomerVisitRecord(Long pkCustomerVisitRecord) {
		this.pkCustomerVisitRecord = pkCustomerVisitRecord;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public ProductType getProductType() {
		return productType;
	}

	public void setProductType(ProductType productType) {
		this.productType = productType;
	}

	public VisitWay getVisitWay() {
		return visitWay;
	}

	public void setVisitWay(VisitWay visitWay) {
		this.visitWay = visitWay;
	}

	public QuestionAnswerSheet getQuestionAnswerSheet() {
		return questionAnswerSheet;
	}

	public void setQuestionAnswerSheet(QuestionAnswerSheet questionAnswerSheet) {
		this.questionAnswerSheet = questionAnswerSheet;
	}

	public Date getVisitDate() {
		return visitDate;
	}

	public void setVisitDate(Date visitDate) {
		this.visitDate = visitDate;
	}

	public Date getVisitRemindDate() {
		return visitRemindDate;
	}

	public void setVisitRemindDate(Date visitRemindDate) {
		this.visitRemindDate = visitRemindDate;
	}

	public Intention getIntention() {
		return intention;
	}

	public void setIntention(Intention intention) {
		this.intention = intention;
	}

	public RecordType getRecordType() {
		return recordType;
	}

	public void setRecordType(RecordType recordType) {
		this.recordType = recordType;
	}

	public CommonUser getSaleConsultant() {
		return saleConsultant;
	}

	public void setSaleConsultant(CommonUser saleConsultant) {
		this.saleConsultant = saleConsultant;
	}

	public String getContents() {
		return contents;
	}

	public void setContents(String contents) {
		this.contents = contents;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Boolean getJoinOtherOrg() {
		return joinOtherOrg;
	}

	public void setJoinOtherOrg(Boolean joinOtherOrg) {
		this.joinOtherOrg = joinOtherOrg;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public Visit getVisit() {
		return visit;
	}

	public void setVisit(Visit visit) {
		this.visit = visit;
	}

}
